﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections;

/// <summary>
/// FlowModel 流程模板设置操作
/// </summary>
public class FlowModel
{
    public int flowMID;
    public string FlowName;
    public int FlowTypeID;
    public string Brief;
    public string UserName;
    public DateTime Addtime;
    public string Status;
	public FlowModel()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}    
    public FlowModel(int modelID)
    {
        this.flowMID=modelID;
        string sqlString = "select * from LCMINFO where FLOWMID=" + this.flowMID;
        DBOperation DBO = new DBOperation();
        SqlDataReader sdr = DBO.GetDataReader(sqlString);
        if (sdr.Read())
        {
            this.FlowName = sdr["FLOWMNAME"].ToString();
            this.FlowTypeID = Convert.ToInt32(sdr["FLOWTYPEID"].ToString());
            this.Brief = sdr["BRIEF"].ToString();
            this.UserName = sdr["USERNAME"].ToString();
            this.Addtime = Convert.ToDateTime(sdr["ADDTIME"].ToString());
            this.Status = sdr["STATUS"].ToString();
            this.flowMID = Convert.ToInt32(sdr["FLOWMID"].ToString());
        }
        sdr.Close();
 
    }
    /// <summary>
    /// AddFlowModel(),流程模板添加方法
    /// </summary>
    public Boolean AddFlowModel()
    {
        string sQueryString;
        sQueryString = "insert into LCMINFO (FLOWMNAME,FLOWTYPEID,BRIEF,USERNAME,STATUS) values  ('";
        sQueryString += this.FlowName + "'," + this.FlowTypeID.ToString() + ",'" + this.Brief + "','" + this.UserName + "','1')";
        DBOperation DBO = new DBOperation();

        if (DBO.ExcuteSql(sQueryString))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    /// <summary>
    /// 删除流程模板
    /// </summary>
    /// <returns>成功则返回true，否则返回false</returns>
    public Boolean DelFlowModel()
    {
        Boolean success = false;
        ArrayList sqlArray = new ArrayList();
        sqlArray.Add("delete from LCMINFO where FLOWMID=" + this.flowMID);
        sqlArray.Add("delete from LCBZMINFO where FLOWMID=" + this.flowMID);
        DBOperation DBO = new DBOperation();
        success = DBO.ExcuteSqls(sqlArray);
        return success;
    }
    /// <summary>
    /// 根据流程模板ID删除流程模板
    /// </summary>
    /// <param name="modelID">流程模板ID</param>
    /// <returns>成功则返回true，否则返回false</returns>
    public Boolean DelFlowModel(int modelID)
    {
        this.flowMID = modelID;
        Boolean success = false;
        ArrayList sqlArray = new ArrayList();
        sqlArray.Add("delete from LCMINFO where FLOWMID=" + this.flowMID);
        sqlArray.Add("delect from LCBZMINFO where FLOWMID=" + this.flowMID);
        DBOperation DBO = new DBOperation();
        success = DBO.ExcuteSqls(sqlArray);
        return success;
    }
    public Boolean UpdateFlowModel()
    {
        bool success = false;
        string sqlString = "update LCMINFO set FLOWMNAME='" + this.FlowName + "',FLOWTYPEID=" + this.FlowTypeID.ToString() + ",BRIEF='" + this.Brief + "',USERNAME='" + this.UserName + "',ADDTIME='" + this.Addtime.ToString() + "',STATUS='" + this.Status + "' where FLOWMID="+this.flowMID.ToString();
        DBOperation DBO = new DBOperation();
        success=DBO.ExcuteSql(sqlString);
        return success;
    }
    /// <summary>
    /// 根据流程模板名称获取流程模板ID
    /// </summary>
    /// <param name="flowName">流程模板名称</param>
    /// <returns>流程模板ID</returns>
    
    public string GetFlowMID(string flowName)
    {
        SqlConnection conn = DBConnection.CreateConnection();
        conn.Open();
        string sqlString = "select FLOWMID from LCMINFO where FLOWMNAME='" + flowName + "' order by ADDTIME desc";
        SqlCommand cmd = new SqlCommand(sqlString, conn);
        string flowMID = cmd.ExecuteScalar().ToString();
        return flowMID;
    }   
  
}
